package middleware

import (
	"github.com/gogf/gf/net/ghttp"
	"net/http"
)

func MiddlewareCors(r *ghttp.Request) {
	corsOptions := r.Response.DefaultCORSOptions()
	//设置只允许某些域名能跨域请求
	corsOptions.AllowDomain = []string{"192.168.90.250:8886"}
	//阻止请求继续向下传递，走到控制器，执行控制器逻辑
	if !r.Response.CORSAllowedOrigin(corsOptions) {
		r.Response.WriteStatus(http.StatusForbidden)
		return
	}
	r.Response.CORS(corsOptions)

	//r.Response.CORSDefault()
	r.Middleware.Next()
}
